(function(e){
    // 点击事件触发生生元素等一系列动作的初始状态
    var bombFlag = true;
    // body节点
    var elBody = document.getElementsByTagName("body")[0];
    // 初始化文字数组下标
    var a_idx = 0;
    elBody.onclick = function(e) {
        if(bombFlag){
            // 坐标
            var ev = e||event,//   IE浏览器兼容
                x = ev.clientX,
                y = ev.clientY;
            // 随机产生文字颜色
            var color1 = Math.floor((Math.random()*255));
            var color2 = Math.floor((Math.random()*255));
            var color3 = Math.floor((Math.random()*255));
            // 初始化定时器
            var _timer = null;
            // 文字数组
            var a = new Array("❤只做第一个我，不做第二个谁❤", "❤用爱生活，你会使自己幸福！用爱工作，你会使很多人幸福❤", "❤当世界给草籽重压时，它总会用自己的方法破土而出❤");
            // 创建节点
            var elSpan = document.createElement("span");
            // 随机节点内容
            a_idx = (a_idx + 1) % a.length;
            // 添加内容到节点
            elSpan.innerHTML = a[a_idx];
            // 初始节点化样式
            elSpan.style.zIndex = 999;
            elSpan.style.position = "fixed";
            elSpan.style.top = y -20 + "px",
                elSpan.style.left = x -10 + "px";
            elSpan.style.color = 'rgb('+color1+','+color2+','+color3+')';
            elSpan.style.fontWeight = "bold";
            elSpan.className = "floatSpan";
            // 将元素追加到body中
            elBody.appendChild(elSpan);
            // 获取追加后的节点
            var el = document.getElementsByClassName("floatSpan")[0];
            // 初始化需要渐变的变量值
            // top值
            var cur_y = y - 20;
            // 透明度
            var cur_opacity = 1;
            // 字体大小
            var cur_fontSize = 14;
            // 创建定时器
            _timer = setInterval(function(){
                // 渐变变量
                cur_y += -10;
                cur_opacity -= 0.1;
                cur_fontSize += 1;
                // 渐变变量赋值（因为有单位的关系  所以不能直接加减  通过中间变量来赋值）
                el.style.top = cur_y + "px";
                el.style.opacity = cur_opacity;
                el.style.fontSize = cur_fontSize + "px";
            },50);
            // 时间到了之后清空定时器  清除刚才添加的元素  并且恢复点击触发事件
            setTimeout(function(){
                clearInterval(_timer);
                elBody.removeChild(el);
                bombFlag = true;
            },500);
        }
        // 暂停点击触发事件
        bombFlag = false;
    };
})();



//下雪
window.onload = function () {
    var Canvas = function (w, h) {
        this.width = w;
        this.height = h;
    }
    Canvas.prototype = {
        init: function () {
            var oC = document.createElement("canvas");
            oC.setAttribute('width', this.width);
            oC.setAttribute('height', this.height);
            oC.setAttribute('id', 'canvas');

            document.body.appendChild(oC);
        }
    }
    var curWinWidth = window.innerWidth,
        curWinHeight = window.innerHeight;
    var oCanvas = new Canvas(curWinWidth, curWinHeight);
    oCanvas.init();

    var oC = document.querySelector('#canvas');
    var width = oC.width, height = oC.height, oGc = oC.getContext('2d');

    function random(min, max) {
        return Math.random() * (max - min) + min;
    }
    var Snow = function () {

    }
    Snow.prototype = {
        init: function () {
            this.x = random(0, width);
            this.y = 0;
            this.r = random(1, 5);
            this.vy = random(3, 5);
        },
        draw: function (cxt) {
            cxt.beginPath();
            cxt.fillStyle = 'white';
            cxt.arc(this.x, this.y + this.r, this.r, 0, Math.PI * 2, false);
            cxt.fill();
            cxt.closePath();
            this.update(cxt);
        },
        update: function (cxt) {
            if (this.y < height - this.r) {
                this.y += this.vy;
            } else {
                this.init();
            }
        }
    }

    var snow = [];
    for (var i = 0; i < 500; i++) {
        setTimeout(function () {
            var oSnow = new Snow();
            oSnow.init();
            snow.push(oSnow);
        }, 10 * i);
    }

    (function move() {
        oGc.clearRect(0, 0, width, height);
        for (var i = 0; i < snow.length; i++) {
            snow[i].draw(oGc);
        }
        requestAnimationFrame(move);
    })();
}











